package com.cal.utms.entity;

import java.io.Serializable;

import javax.persistence.*;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.cal.utms.logAudit.AuditLogInt;
import com.cal.utms.util.ValueConvert;

import java.util.List;

/**
 * The persistent class for the issuer database table.
 * 
 */
@Entity
@Table(name = "issuer")
@NamedQuery(name = "Issuer.findAll", query = "SELECT i FROM Issuer i")
public class Issuer implements Serializable, AuditLogInt {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Column(name = "ADDRESS")
	private String address;

	@Column(name = "CODE")
	private String code;

	@Column(name = "CREDIT_RATING")
	private Integer creditRating;

	@Column(name = "EMAIL")
	private String email;

	@Column(name = "FAX")
	private String fax;

	@Column(name = "NAME")
	private String name;

	@Column(name = "PHONE")
	private String phone;

	@Column(name = "RATING_GIVEN_BY")
	private String ratingGivenBy;

	@Column(name = "ISSURE_CATEGORY_ID")
	private Integer issuerType;

	@Column(name = "COMPANY_REG_NO")
	private String companyRegNo;

	// bi-directional many-to-one association to IssuerBankAccount
	@OneToMany(mappedBy = "issuer", fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<IssuerBankAccount> issuerBankAccounts;

	// bi-directional many-to-one association to IssuerContactPerson
	@OneToMany(mappedBy = "issuer", fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
	@Fetch(value = FetchMode.SUBSELECT)
	private List<IssuerContactPerson> issuerContactPersons;

	public Issuer() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getCreditRating() {
		return this.creditRating;
	}

	public void setCreditRating(Integer creditRating) {
		this.creditRating = creditRating;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFax() {
		return this.fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getRatingGivenBy() {
		return this.ratingGivenBy;
	}

	public void setRatingGivenBy(String ratingGivenBy) {
		this.ratingGivenBy = ratingGivenBy;
	}

	public Integer getIssuerType() {
		return this.issuerType;
	}

	public void setIssuerType(Integer issuerType) {
		this.issuerType = issuerType;
	}

	public List<IssuerBankAccount> getIssuerBankAccounts() {
		return this.issuerBankAccounts;
	}

	public void setIssuerBankAccounts(List<IssuerBankAccount> issuerBankAccounts) {
		this.issuerBankAccounts = issuerBankAccounts;
	}

	public IssuerBankAccount addIssuerBankAccount(IssuerBankAccount issuerBankAccount) {
		getIssuerBankAccounts().add(issuerBankAccount);
		issuerBankAccount.setIssuer(this);

		return issuerBankAccount;
	}

	public IssuerBankAccount removeIssuerBankAccount(IssuerBankAccount issuerBankAccount) {
		getIssuerBankAccounts().remove(issuerBankAccount);
		issuerBankAccount.setIssuer(null);

		return issuerBankAccount;
	}

	public List<IssuerContactPerson> getIssuerContactPersons() {
		return this.issuerContactPersons;
	}

	public void setIssuerContactPersons(List<IssuerContactPerson> issuerContactPersons) {
		this.issuerContactPersons = issuerContactPersons;
	}

	public IssuerContactPerson addIssuerContactPerson(IssuerContactPerson issuerContactPerson) {
		getIssuerContactPersons().add(issuerContactPerson);
		issuerContactPerson.setIssuer(this);

		return issuerContactPerson;
	}

	public IssuerContactPerson removeIssuerContactPerson(IssuerContactPerson issuerContactPerson) {
		getIssuerContactPersons().remove(issuerContactPerson);
		issuerContactPerson.setIssuer(null);

		return issuerContactPerson;
	}

	@Transient
	@Override
	public Long getLogId() {
		return ValueConvert.toLong(this.id);
	}

	@Transient
	@Override
	public String getLogDeatil() {
		StringBuilder sb = new StringBuilder();
		sb.append("Issuer Id : ").append(id).append("Issuer Code : ").append(code);

		return sb.toString();
	}

	public String getCompanyRegNo() {
		return companyRegNo;
	}

	public void setCompanyRegNo(String companyRegNo) {
		this.companyRegNo = companyRegNo;
	}

}